<?php
/**
 * Session.php
 * Thu Jun 07 11:58:34 JST 2007
 * @author qqinxl
 * @package models_html
 * LICENSE 
 *
 * @copyright  Copyright (c) lin-international
 */
/**
 * @package models_html
 */
class HtmlHelper_Session{
	/**
	 * 从session里取值
	 * @param string $sessionname
	 * @param string $key
	 * @return mix
	*/
	static function getValue($sessionname,$key=null){
		if(empty($sessionname)){
			return null;
		}
		if(($key == 'password' or $key == 'password2') and $sessionname != 'loginSession'){
			return null;
		}
		
		if(isset($_SESSION[$sessionname])){
			if(is_array($_SESSION[$sessionname]) and !empty($key)){
				if(isset($_SESSION[$sessionname][$key])){
					return $_SESSION[$sessionname][$key];
				}else{
					return null;
				}
			}else{
				return $_SESSION[$sessionname];
			}
		}else{
			return null;
		}
	}
	/**
	 * 从cookie里取值
	 * @param string $cookiename
	 * @param string $key
	 * @return mix
	*/
	static function getValueFromCookie($cookiename,$key=null){
		if(empty($cookiename)){
			return null;
		}
		if(isset($_COOKIE[$cookiename])){
			if(is_array($_COOKIE[$cookiename]) and !empty($key)){
				if(isset($_COOKIE[$cookiename][$key])){
					return $_COOKIE[$cookiename][$key];
				}else{
					return null;
				}
			}else{
				return $_COOKIE[$cookiename];
			}
		}else{
			return null;
		}
	}
}